package com.lx.video.web;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lx.bean.Result;
import com.lx.bilibili.annotition.LoginValidator;
import com.lx.bilibili.entity.User;
import com.lx.bilibili.entity.Video;
import com.lx.bilibili.entity.VideoEx;
import com.lx.bilibili.util.VideoRecommender;
import com.lx.video.dao.VideoExMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("search")
public class SearchController {


    @Autowired
    VideoExMapper videoExMapper;


    @RequestMapping("searchByText")
    public List<VideoEx> searchByText(String searchText){
        return videoExMapper.searchByText(searchText);
    }
    
    @RequestMapping("comprehensiveRank")
    public Result comprehensiveRank(String searchText){

        VideoRecommender videoRecommender = new VideoRecommender();
        return new Result(1, "success", videoRecommender.recommendVideos(this.searchByText(searchText)));

    }

    @RequestMapping("mostPlay")
    public Result mostPlay(String searchText){
        return new Result(1, "success", videoExMapper.mostPlay(searchText));

    }

    @RequestMapping("newPublish")
    public Result newPublish(String searchText){
        LambdaQueryWrapper<Video> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Video::getState, 1).like(Video::getVname, searchText).orderByDesc(Video::getTime);
        List<Video> videoExes = videoExMapper.selectList(lqw);
        return new Result(1, "success", videoExMapper.newPublish(searchText));

    }

    @RequestMapping("mostDanmu")
    public Result mostDanmu(String searchText){
        LambdaQueryWrapper<Video> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Video::getState, 1).like(Video::getVname, searchText).orderByDesc(Video::getDanmuCount);
        List<Video> videoExes = videoExMapper.selectList(lqw);
        return new Result(1, "success", videoExMapper.mostDanmu(searchText));
    }

    @RequestMapping("searchByTextAndType")
    public Result searchByTextAndType(String searchText){
        searchText = "%" + searchText + "%";
        return new Result(1, "success", videoExMapper.searchByTextAndType(searchText));
    }

}
